package com.leyou.auth.feign;

import com.leyou.auth.job.TokenHolder;
import com.leyou.common.constant.LyConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * RequestInterceptor
 * feign提供的拦截器，对所有feign请求做处理。
 */
@Component
public class AuthFeignInterceptor implements RequestInterceptor {

    @Autowired
    private TokenHolder tokenHolder;

    @Override
    public void apply(RequestTemplate template) {
        template.header(LyConstants.SERVER_AUTH_HEADER_KEY, tokenHolder.getToken());
    }
}
